#ifndef DOLLANIM_H
#define DOLLANIM_H

#include "../common/win32dialogs.h"
#include "../engine/engine.h"


class DollAnimApp;


class DollModel : public GLRagdoll
{
public:
    DollModel(GLObject *obj);
    virtual void onUpdate(float dt);
    void init(DollAnimApp* app);
    void setAction(int act);
    void selectPart(int part);
    inline int getSelectedPart() { return selected_part; }
    inline DollAnimApp* getDollApp() { return my_app; }
private:
    int next_anim;
    int cur_anim;
    int selected_part;
    DollAnimApp *my_app;
};


class DollPart : public GLBehavior
{
public:
    DollPart(GLObject* obj) : GLBehavior(obj) { }
    virtual void onRender();
    inline void init(DollModel* dm, int id) { doll = dm; partId = id; }
private:
    DollModel* doll;
    int partId;
};


class GridGround : public GLBehavior
{
public:
    GridGround(GLObject* obj) : GLBehavior(obj) { }
    virtual void onRender();
    inline void init(int w, int h) { size.set(w, h); }
private:
    vector2i size;
};


class DollAnimApp : public GLClient
{
public:
	DollAnimApp(GLEngine* engine);
	virtual ~DollAnimApp();

	virtual void onEnter();
	virtual void onLeave();
	virtual void onEvent(GLEvent e);
	virtual void onUpdate(float dt);
	virtual void onDraw();
    virtual void onGuiDraw(GLGuiControl* ctl);

    vector2f axisCenter;
    vector2f axisX;
    vector2f axisY;
    vector2f axisZ;
    bool isPlaying;

    void setCurrentFrame(int frame);
    void rotateSelectedPart(int axis, float val);
    void playAnimation();
    void stopAnimation();
    void applyChanges();

private:
    GLScene *scene;
    GLCamera camera;
    GLFont *font;
    DollModel *ragdoll;
    int selAxis;
    float lastDist;
    RagdollAnimation animation;
    int currentFrame;
    int totalFrames;
    GLRagdoll *tempdoll;
    String animationName;
    int animationSpeed;
    bool showPartInfo;
    vector3f copyPart;
    //gui
    GLGuiControl *fileLabel;
    GLGuiControl *frameLabel;
    GLGuiControl *controlPanel;
    GLGuiControl *playingPanel;
    GLGuiControl *playingLabel;
    GLGuiControl *speedLabel;
};


#endif // DOLLANIM_H
